﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Imaging;
//using System.Drawing;
using System.IO;

namespace Asomy.View
{
    class PaintAreaView
    {
        public Camera m_camera = new Camera();

        public void DrawPaintArea(ref Canvas a_canvas,byte[] a_image,int a_width,int a_height)
        {
            try
            {                             
                a_canvas.Width = a_width * m_camera.X_scale;
                a_canvas.Height = a_height * m_camera.Y_scale;                

                Image myImage = new Image();                

                myImage.Source = CreateImage(a_width, a_height, a_image);              
                
                a_canvas.Children.Clear();

                myImage.Width = a_canvas.Width;
                myImage.Height = a_canvas.Height;               
                
                a_canvas.Children.Add(myImage);                       
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }                       
        }

        public BitmapSource CreateImage(int a_width, int a_height, byte[] a_image)
        {            
            PixelFormat pf = PixelFormats.Bgra32;

            int rawStride = (a_width * pf.BitsPerPixel + 7) / 8;

            BitmapSource bitmap = BitmapSource.Create(a_width, a_height,
               96, 96, pf, null,
               a_image, rawStride);          
  
            return bitmap;
        }       
    }
}
